<?php


namespace app\tt\controller;


use app\common\model\ProductCps;
use app\common\model\WechatShareLink;
use think\Controller;
use think\Exception;
use think\facade\Request;
use app\common\model\Product as ProductModel;

class Product extends  Controller
{

    //获取产品列表
    public function index()
    {
        $page=Request::param('page',1);
        $list=ProductModel::where(['status'=>1])
            ->where('test_type','<>','kuaishou')
            ->page($page,100)->field(['data'],true)->select();
        $this->result($list,200,'成功');
    }

    //推荐列表
    public function recommend()
    {
        $list=ProductModel::where(['recommend'=>1,'status'=>1]) ->where('test_type','<>','kuaishou')->field(['data'],true)->select();
        $this->result($list,200,'成功');
    }

    //产品详情
    public function read()
    {
        $product_id=Request::param('product_id',0);

        $no=Request::param('url_no',0);
        $mini_app_code=WechatShareLink::where('no',$no)->value('mini_app_code');

        if($mini_app_code=='test'|| $mini_app_code==null){
            $info=ProductModel::get($product_id);
        }
        if($mini_app_code=='test_cps'){
            $info=ProductCps::get($product_id);
        }
        try {
            if($mini_app_code=='test'){
                ProductModel::where('id', $product_id)->setInc('count');
            }
            if($mini_app_code=='test_cps'){
                ProductCps::where('id', $product_id)->setInc('count');
            }
        } catch (Exception $e) {
        };

        $this->result($info,200,'成功');
    }


}
